﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TopMainForm.aspx.cs" Inherits="App_System_TopMainForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../../style/style.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="../../javascript/commons.aspx"></script>
    <script language="javascript">
    function ajaxRelease() {
        for(var i=0; typeof(requests)!='undefined' && i<requests.length; i++) {
            if( requests[i].obj==this.request ) {
                requests[i].obj.abort();
                requests[i].obj = null;
                requests[i] = null;
                requests.splice(i, 1);
                break;
            }
        }
    }
    </script>
</head>
<body topmargin="0" leftmargin="0" style="margin: 0"
    onload="init()">
    <form id="form1" runat="server">
        <div>
            
    <table border="0" width="100%" style="height: 170px" cellpadding="0" cellspacing="0">
      <tr> 
        <td width="751" background="../../images/logo-left.jpg">
            <table border="0" width="751" height="170" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="425"><br /></td>
                    <td style="color:#ffffff;line-height:16px;padding-top:10px" valign="top">
                    编号: <%=this.employeeId %> <br />
                    姓名: <%=this.employeeName %> <br />
                    职务: <%=this.employeeJob %>
                    </td>
                </tr>
            </table>
        </td>
        <td width="470"> 
        <img src="../../images/logo-right.jpg" usemap="#linkMap" border="0"/>
        <map name="linkMap">
        <area shape="circle" coords="305,149,10" href="#" title="前一页" onclick="top.window.mainFrame.history.go(endsWith(top.window.mainFrame.location.href,'PortalMainForm.aspx')?0:-1)"/>
        <area shape="circle" coords="332,149,10" href="#" title="后一页" onclick="top.window.mainFrame.history.go(1)" />
        <area shape="circle" coords="354,149,10" href="#" title="返回主页" onclick="top.window.mainFrame.location.href='../../App/System/PortalMainForm.aspx'"/>
        <area shape="circle" coords="379,149,10" href="#" title="修改密码" onclick="window.open('<%=Request.ApplicationPath %>/App/Commons/PassForm.aspx', 'PassForm', 'scrollbars,resizable,height=200,width=300')"/>
        <area shape="circle" coords="405,149,10" href="#" title="显示帮助"/>
        <area shape="circle" coords="429,149,10" href="#" title="退出ERP"  onclick="if(confirm('确定要退出系统？')){top.window.location.href='<%=Request.ApplicationPath %>/System/Auth/Logon.aspx'}"/>
        </map> 
        </td>
        <td>
          <img id="imgMessage" src="../../images/mail.gif" border="0" style="visibility:hidden"/> 
          <span id="messageReminder" onclick="javascript:"></span>
          <img id="imgAlarm" src="../../images/mail.gif" border="0" style="visibility:hidden"/> 
          <a href='#'><span id="alarmReminder" onclick="top.window.mainFrame.location.href='../../App/Search/CommunityMonitorSrhForm.aspx'"></span></a>
          <span id="PlaneTime"></span>
          <input type="hidden" id="countDownTimeAlarm" value="0" /> 
          <input type="hidden" id="countDownTime" value="0" /> 
        </td>
      </tr>
    </table>
    
        </div>
    </form>
</body>
</html>


    <script language="javascript">
        function processCallMemo() {
            var e;
            
            try {
                var response = CommonAjaxUtils.ProcessCallMemo();
                // 释放request对象
                response.release = ajaxRelease;
                response.release();
            }
            catch(e) {
                // alert("processCallMemo: "+e.message);
            }

            setTimeout("processCallMemo()", 15000);
        }

        function doDisplayEmp(visible) {
            document.getElementById("emp").style.visibility = (visible)?"visible":"hidden";
        }

        function displayTime() {
		    document.getElementById("PlaneTime").innerText = (new Date()).toLocaleTimeString()+' ';
		    setTimeout("displayTime()", 800);
	    }
	    
	    function displayNavigate(lnkName, lnkUrl, title) {
	        var rNode = document.getElementById("navigate");
	        
	        if( rNode!=null ) {
	            while(rNode.childNodes.length!=0) {
	                rNode.removeChild( rNode.childNodes[0] );
	            }

	            if( arguments.length!=3 ) {
                    return;    	            
	            }

	            var divNode = document.createElement("DIV");
                divNode.style.cssText="font-size:12px";

	            divNode.appendChild( document.createTextNode(title) );

	            rNode.appendChild( divNode );
	        }
	    }

	    function openBbs() {
            window.open("http://www.qinheyuan.com/bbs/index.php", "_bbs");
	    }
	    
	    function openBlog() {
	        window.open("http://www.qinheyuan.com/space/index.php", "_blog");
	    }
	    
	    function openMail() {
	        window.open("http://mail.qinheyuan.com/", "_mail");
	    }

	    function scrollChange() {
            window.scrollTo(0,0);
        }
        
        // set time frequency to get new message from sever
        function getNewMessage(cycle) {
            var e;
            try {
                CommonAjaxUtils.GetEmpMessage(
                    function(response) {
                        try {
                            var targetData = response.value;
	                        var msgTable;
	                        msgTable = (top.window.mainFrame==null) ? null : top.window.mainFrame.document.getElementById("tblMsgBoard");
    	                    // refresh work area message board
	                        if (msgTable != null && typeof(msgTable) == "object"){
                                bindMsgTable(msgTable,targetData);
	                        }

                            stopGlitter();

    	                    // refresh top tool bar
	                        if (targetData != null 
	                            && typeof(targetData) == "object" 
	                            && targetData.length > 0) {
    	                        var newMsgCnt = getNewMsgCount(targetData);
    	                        if (newMsgCnt > 0) {
	                                document.getElementById("countDownTime").value = <%=msgGlitterCount %>;
                                    showToolBarNewMessage(<%=msgGlitterCount %>,newMsgCnt);	        	            
                                }
	                        }
                            
                            // 进入下一个循环
                            if( cycle ) {
                                setTimeout("getNewMessage(true)", <%=refreshMsgMSeconds %>);            
                            }

                            // 释放request对象
                            response.release = ajaxRelease;
                            response.release();
	                    }
                        catch(e) {
                            alert('getNewMessage'+e.message);
                        }
                    }
                );
               
		    }
            catch(e) {
                alert('getNewMessage: '+e.message);
            }
        }
        //报警消息提示
        function getNewAlarmMessage(cycle) {
            var e;            
            try {
                CommonAjaxUtils.FindAlarm(
                    function(response) {    
                        try {              
                            var targetData = response.value;               		    		        		        		        
                            var msgTable;
    	                    // alert(targetData.length);
    	                    // refresh top tool bar
	                        if (targetData != null 
	                            && typeof(targetData) == "object" 
	                             ) {
                                stopAlarmGlitter();
	                            if(targetData.length > 0)
	                            {
	                               document.getElementById("countDownTimeAlarm").value = <%=msgGlitterCount %>;
	                               showToolBarNewAlarmMessage(<%=msgGlitterCount %>,targetData.length);
	                            }
	                        }

                            // 进入下一个循环
	                        if( cycle ) {
                                setTimeout("getNewAlarmMessage(true)", 2000);
                            }
                            
                            // 释放request对象
                            response.release = ajaxRelease;
                            response.release();
	                    }
                        catch(e) {
                            alert('getNewAlarmMessage'+e.message);
                        }
                    }
                );
		    }
            catch(e) {
                alert('getNewAlarmMessage: '+e.message);
            }
        }
        
        var page_TimerID = null;
        var page_Alarm_TimerID = null;
        function showToolBarNewAlarmMessage(countDown,countMsg) {
            var glitter;
            var obj = document.getElementById("alarmReminder");
            obj.innerHTML = "您收到了" + countMsg +"则报警信息！";
            document.getElementById("imgAlarm").style.visibility = "visible";
            if (obj.style.color == 'red') {
                obj.style.color = 'white';
                glitter = <%=msgGlitterMSeconds %>;
            } else {
                obj.style.color = 'red';
                glitter = <%=msgGlitterMSeconds*2 %>;
            }
            
            if (parseInt(countDown) > 0) {
               // countDown = parseInt(countDown) - 1;             
                page_Alarm_TimerID = setTimeout("showToolBarNewAlarmMessage(" + countDown + "," + countMsg + ")", glitter);
            }
            else {                
                stopAlarmGlitter();
            }
        }
        function stopAlarmGlitter(){
            
            document.getElementById("alarmReminder").innerHTML = " ";           
            document.getElementById("alarmReminder").style.color = 'white';           
            document.getElementById("imgAlarm").style.visibility = "hidden";
            if (page_Alarm_TimerID != null && !isNaN(page_Alarm_TimerID)) {
                window.clearTimeout(page_Alarm_TimerID);
                page_Alarm_TimerID = null;    
            }
        }

        ////////////////////////////
        function getNewMsgCount(objData) {
            if (objData == null) { return 0; }
            var retCnt = 0;
            for(var i = 0; i < objData.length; i++) {  
                var status = objData[i].MessageStatus;
                if (status == "1") {
                    retCnt = retCnt + 1;
                }
            }
            return retCnt;
        }
        
        function showToolBarNewMessage(countDown,countMsg) {
            var glitter;
            var obj = document.getElementById("messageReminder");
            obj.innerHTML = "您收到了" + countMsg +"则新消息！";
            document.getElementById("imgMessage").style.visibility = "visible";
            if (obj.style.color == 'blue') {
                obj.style.color = 'white';
                glitter = <%=msgGlitterMSeconds %>;
            } else {
                obj.style.color = 'blue';
                glitter = <%=msgGlitterMSeconds*2 %>;
            }
            
            if (parseInt(countDown) > 0) {
                countDown = parseInt(countDown) - 1;             
                page_TimerID = setTimeout("showToolBarNewMessage(" + countDown + "," + countMsg + ")", glitter);
            }
            else {                
                stopGlitter();
            }
        }
        
        // bind message table data
        function bindMsgTable(objTable,objData) { 
            if (objData == null) { return; }
                  									
		    // del rows                        
		    for(var i=objTable.rows.length - 1; i >= 0; i--) {				
			    objTable.deleteRow(i);				
		    }
		    
		    // readd rows
		    var headRow = objTable.insertRow(objTable.rows.length);
		    var headCell = headRow.insertCell(headRow.cells.length);
		    headCell.style.height = "16px";
		    // headCell.className = "TD_headrow_style";
		    
		    var maxDispCnt = objData.length > <%=msgMaxDispCount %> ? <%=msgMaxDispCount %> : objData.length;
            for(var i = 0; i < maxDispCnt; i++) {                      
                var id = objData[i].MessageId;
                var title = objData[i].Subject;
                var origin = objData[i].EmployeeName;
                var status = objData[i].MessageStatus;
                if (title == null) {
                    title = "(无主题)";
                }
                
                var elementRow = objTable.insertRow(objTable.rows.length);
		        elementRow.id = "msgRow" + i;
		        
                var elementCol = elementRow.insertCell(elementRow.cells.length);
                elementCol.align = "left";
                elementCol.className = "TD_row_style_message"; 
                if (status == "1") {
                    elementCol.className = "TD_row_style_new_message";                
                }
                //elementCol.innerHTML = "<A href=\"" + strCmd + "\" >" + name +"</A>";
                var elementLink = top.window.mainFrame.document.createElement("A");
                elementLink.setAttribute("id", "msgLink" + i);                
                elementLink.setAttribute("href", "javascript:top.window.topFrame.getNewMessage();window.open('../Input/MessageReadForm.aspx?MESSAGE_ID=" + id +"','_blank','scrollbars,resizable,height=550,width=520');void(0);");
                elementLink.setAttribute("innerText", origin + "：" + title); 
                //elementLink.setAttribute("style", "color:red");
                elementCol.appendChild(elementLink);
            }
        }
        
        function stopGlitter(){
            document.getElementById("countDownTime").value = 0;
            document.getElementById("messageReminder").innerHTML = " ";           
            document.getElementById("messageReminder").style.color = 'white';           
            document.getElementById("imgMessage").style.visibility = "hidden";
            if (page_TimerID != null && !isNaN(page_TimerID)) {
                window.clearTimeout(page_TimerID);
                page_TimerID = null;    
            }
        }

        // set time frequency to get new message from sever
        function getNotifyMessage(cycle) {
            var e;            
            try {
                CommonAjaxUtils.GetNotifyMessage(
                    function(response) {
                        try {                                            
                            var targetData = response.value;
	                        var msgTable;
	                        msgTable = (top.window.mainFrame==null) ? null : top.window.mainFrame.document.getElementById("tblNotifyMsgBoard");

    	                    // refresh work area message board
	                        if (msgTable != null && typeof(msgTable) == "object"){
                                bindMsgTable(msgTable,targetData);
	                        }

                            if( cycle ) {
                                // 进入下一个循环
                                setTimeout("getNotifyMessage(true)", <%=refreshMsgMSeconds %>);
                            }
                            
                            // 释放request对象
                            response.release = ajaxRelease;
                            response.release();
	                    }
                        catch(e) {
                            alert(e.message);
                        }
                    }
                );
		    }
            catch(e) {
                alert(e.message);
            }
        }

        function init() {
            displayTime();
            processCallMemo();
            getNewMessage(true);
            getNotifyMessage(true);
            getNewAlarmMessage(true); 
        }

		window.onscroll = scrollChange;
    </script>